var rem;
(function (doc, win) {
    var docEl = doc.documentElement,
        resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
        recalc = function () {
            var clientWidth = docEl.clientWidth;
            if (!clientWidth) return;
            rem = 20 * (clientWidth / 375);
            docEl.style.fontSize = rem + 'px';
        };

    if (!doc.addEventListener) return;
    win.addEventListener(resizeEvt, recalc, false);
    doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);

(function ($) {
    $.fn.picLazyLoad = function (settings) {
        var $this = $(this),
            _winScrollTop = 0,
            _winHeight = $(window).height();

        settings = $.extend({
            threshold: 0, // 提前高度加载
            placeholder: ''
        }, settings || {});

        // 执行懒加载图片
        lazyLoadPic();

        // 滚动触发换图
        $(window).on('scroll', function () {
            _winScrollTop = $(window).scrollTop();
            lazyLoadPic();
        });

        // 懒加载图片
        function lazyLoadPic() {
            $this.each(function () {
                var $self = $(this);
                // 如果是img
                if ($self.is('img')) {
                    if ($self.attr('data-original')) {
                        var _offsetTop = $self.offset().top;
                        if ((_offsetTop - settings.threshold) <= (_winHeight + _winScrollTop)) {
                            $self.attr('src', $self.attr('data-original'));
                            $self.removeAttr('data-original');
                        }
                    }
                    // 如果是背景图
                } else {
                    if ($self.attr('data-original')) {
                        // 默认占位图片
                        if ($self.css('background-image') == 'none') {
                            $self.css('background-image', 'url(' + settings.placeholder + ')');
                        }
                        var _offsetTop = $self.offset().top;
                        if ((_offsetTop - settings.threshold) <= (_winHeight + _winScrollTop)) {
                            $self.css('background-image', 'url(' + $self.attr('data-original') + ')');
                            $self.removeAttr('data-original');
                        }
                    }
                }
            });
        }
    }
})(Zepto);
var cc = window.cc || {};
cc.programs = new function () {
    "use strict";
    var pro = this;

    pro.user = function () {

        $.ajax({
            url: io.userInfo.info,
            type: 'get',
            data: {},
            dataType: 'json',
            success: function (data) {
                console.log(data)
                if (data.resultCode == 1000) {
                    if (data.user.headimgurl) {
                        $(".head-img").attr("src", data.user.headimgurl);
                    }
                    $(".user-name").html(data.user.nickname);
                } else {
                    $.tips({
                        content: '服务器忙...',
                        stayTime: 2000,
                        type: "warn"
                    });
                    $(".ui-poptips-cnt i").addClass("icon iconfont icon-tishi");
                }
            },
            error: function () {
                $.tips({
                    content: '服务器忙...',
                    stayTime: 2000,
                    type: "warn"
                });
                $(".ui-poptips-cnt i").addClass("icon iconfont icon-tishi");
            }
        });

        $('li,.icon-shezhi1').tap(function () {
            if ($(this).data('href')) {
                location.href = $(this).data('href');
            }
        });
        function Slide() {
            var lefts = parseInt($(".sea-bottom .wave1").css("left"));

            function slideLeft() {
                lefts--;
                $(".sea-bottom .wave1").css("left", lefts);
                if (Math.abs(lefts) > parseInt($(".sea-bottom .wave1").width()) / 2) {
                    lefts = 0;
                }
            }

            var rights = parseInt($(".sea-bottom .wave2").css("right"));

            function slideRight() {
                rights--;
                $(".sea-bottom .wave2").css("right", rights);
                if (Math.abs(rights) > parseInt($(".sea-bottom .wave2").width()) / 2) {
                    rights = 0;
                }
            }

            setInterval(slideLeft, 35);
            setInterval(slideRight, 35);
        }

        return Slide();
    };

    pro.userInfo = function () {
        //获取用户信息
        $.ajax({
            url: io.userInfo.info,
            type: 'get',
            data: {},
            dataType: 'json',
            beforeSend: function () {
                loadding = $.loading({
                    content: '请稍后...'
                })
            },
            success: function (data) {
                // console.log(data)
                if (data.resultCode == 1000) {
                    if (data.user.headimgurl) {
                        $(".user-img img").attr("src", data.user.headimgurl);
                    }
                    $(".user-name").html(data.user.nickname);
                    $(".userName").val(data.user.userName);
                    $(".userPho").val(data.user.tel);
                    $(".userAddress").val(data.user.country + data.user.province + data.user.city);
                    $(".sex input[data-sex=\"" + data.user.sex + "\"]").attr("checked", "checked").parent().siblings().remove();
                } else {
                    $.tips({
                        content: '服务器忙...',
                        stayTime: 2000,
                        type: "warn"
                    });
                    $(".ui-poptips-cnt i").addClass("icon iconfont icon-tishi");
                }
                loadding.loading("hide");
            },
            error: function () {
                loadding.loading("hide");
                $.tips({
                    content: '服务器忙...',
                    stayTime: 2000,
                    type: "warn"
                });
                $(".ui-poptips-cnt i").addClass("icon iconfont icon-tishi");
            }
        });

        pro.user();
        // $(".ui-form-item-radio label").tap(function () {
        //     $(this).siblings().find("input").attr("checked", null);
        //     $(this).find("input").attr("checked", "checked");
        //     // alert($(".ui-form-item-radio label").find("input[checked=checked]").parent().text())
        // });

        $(".xiugai").tap(function () {
            $(this).html("");
            $(".yzm-box").show();
        });
        var yzm = $('.yzm');
        var loadding;
        yzm.tap(function () {
            $.ajax({
                url: io.userInfo.yzm,
                type: 'get',
                data: {},
                dataType: 'json',
                beforeSend: function () {
                    loadding = $.loading({
                        content: '请稍后...'
                    })
                },
                success: function (data) {
                    time();
                    loadding.loading("hide");
                },
                error: function () {
                    loadding.loading("hide");
                    $.tips({
                        content: '服务器忙...',
                        stayTime: 2000,
                        type: "warn"
                    });
                    $(".ui-poptips-cnt i").addClass("icon iconfont icon-tishi");
                }
            });
        });
        $(".sub").click(function () {
            var name = $(".userName").val();
            var phone = $(".userPho").val();
            var sex = $(".sex input[checked=checked]").data("sex");
            var address = $(".userAddress").val();
            if (!name) {
                $.dialog({
                    title: '',
                    content: '请输入您的姓名',
                    button: ["确认"]
                });
                return;
            }
            if (!phone) {
                $.dialog({
                    title: '',
                    content: '请输入您的手机号码',
                    button: ["确认"]
                });
                return;
            }
            if (phone && !(/0?(13|14|15|17|18)[0-9]{9}/.test(phone))) {
                $.dialog({
                    title: '',
                    content: '请输入正确的手机号码',
                    button: ["确认"]
                });
                return;
            }
            // if (!address) {
            //     $.dialog({
            //         title: '',
            //         animation: 'up',
            //         content: '请输入您的地址',
            //         button: ["确认"]
            //     });
            //     return;
            // }
            var loadding;
            $.ajax({
                url: io.userInfo.editInfo,
                type: 'get',
                data: {
                    userName: name,
                    tel: phone,
                    sex: sex
                },
                dataType: 'json',
                beforeSend: function () {
                    $(".sub").attr("disabled", "disabled");
                    loadding = $.loading({
                        content: '请稍后...'
                    })
                },
                success: function (data) {
                    $(".sub").removeAttr("disabled");
                    // console.log(data);
                    loadding.loading("hide");
                    $.tips({
                        content: "操作成功",
                        stayTime: 2000,
                        type: "success"
                    });
                    $(".ui-poptips-cnt i").addClass("icon iconfont icon-chenggong");
                },
                error: function () {
                    loadding.loading("hide");
                    $(".sub").removeAttr("disabled");
                    $.tips({
                        content: '服务器忙...',
                        stayTime: 2000,
                        type: "warn"
                    });
                    $(".ui-poptips-cnt i").addClass("icon iconfont icon-tishi");
                }
            });

        });

        function time() {
            yzm.off('tap').attr("disabled", "disabled").css({
                "font-size": "1.5rem",
                "color": "#18b4ed"
            });
            var timel = 5;
            go();
            var timer = setInterval(go, 1000);

            function go() {
                yzm.html(timel);
                if (timel == 0) {
                    clearInterval(timer);
                    yzm.html('重新发送').attr("disabled", null).css({
                        "font-size": "16px",
                        "color": "#fff"
                    });
                    yzm.on('tap', time);
                }
                timel--;
            }
        }
    };

    pro.list = function () {
        var list = $(".mList");
        var img = list.find(".img-box");
        var active = list.find(".img-box.active");
        var i = 0;

        // document.querySelector('body').addEventListener('touchstart', function (e) {
        //     e.preventDefault();//禁止微信下拉
        // });
        list.on("touchstart", function (e) {
            e.preventDefault();//禁止微信下拉
        });
        // img.eq(0).height(img.eq(0).find("img").height());
        img.eq(0).height("18.75rem");
        img.eq(0).find('p').eq(1).addClass("active");
        list.swipeUp(function () {
            i++;
            if (i > img.length - 1) {
                i = img.length - 1;
            }
            img.eq(i).height(img.eq(i).find("img").height()).siblings().height("5rem");
            list.css("top", -5 * i + "rem").find('p').removeClass("active");
            img.eq(i).find('p').eq(1).addClass("active");
        });
        list.swipeDown(function () {
            i--;
            if (i < 0) {
                i = 0;
            }
            img.eq(i).height(img.eq(i).find("img").height()).siblings().height("5rem");
            list.css("top", -5 * i + "rem").find('p').removeClass("active");
            img.eq(i).find('p').eq(1).addClass("active");
        });
    };
    pro.sign = function () {
        var backingStore, ratio;
        //解决移动端canvas不清晰
        (function (prototype) {
            prototype.getContext = (function (_super) {
                return function (type) {
                    var context = _super.call(this, type);
                    if (type === '2d') {
                        backingStore = context.backingStorePixelRatio ||
                            context.webkitBackingStorePixelRatio ||
                            context.mozBackingStorePixelRatio ||
                            context.msBackingStorePixelRatio ||
                            context.oBackingStorePixelRatio ||
                            context.backingStorePixelRatio || 1;
                        ratio = (window.devicePixelRatio || 1) / backingStore;
                        if (ratio > 1) {
                            this.style.height = this.height + 'px';
                            this.style.width = this.width + 'px';
                            this.width *= ratio;
                            this.height *= ratio;
                        }
                    }
                    return context;
                };
            })(prototype.getContext);
        })(HTMLCanvasElement.prototype);

        $.fn.signPer = function (settings) {
            function radius(e) {
                return Math.PI / 180 * e;
            }

            var r = $(this);
            this.draw = function (percent) {
                if (typeof percent !== 'undefined') {
                    settings.percentage = percent;
                }
                var ctx = r[0].getContext("2d");
                var hw = r.width() / 2;
                var hh = r.height() / 2;
                var u = 100;
                var a = 0;
                var nums = 0;
                var startPos = 0;
                var f = function (e) {
                    var t = radius(360) / u;
                    return t * e;
                };
                ctx.scale(ratio, ratio);
                ctx.lineWidth = settings.lineWidth;
                ctx.strokeStyle = settings.lineColour;
                var l = function (s, u) {
                    s = s || f(a);
                    u = u || f(a + 1);
                    ctx.clearRect(0, 0, r.width(), r.height());
                    if (settings.showRemaining === true) {
                        ctx.beginPath();
                        ctx.strokeStyle = settings.remainingLineColor;
                        ctx.arc(hw, hh, settings.diameter, 0, 360);
                        ctx.stroke();
                        ctx.closePath();
                    }
                    ctx.strokeStyle = settings.lineColor;
                    ctx.beginPath();
                    if (settings.roundedLine === true) {
                        ctx.lineCap = 'round';
                    }
                    else {
                        ctx.lineCap = 'butt';
                    }
                    startPos = 1.5 * Math.PI;
                    ctx.arc(hw, hh, settings.diameter, startPos, u + startPos);
                    ctx.stroke();
                    ctx.closePath();
                    if (settings.showText === true) {
                        ctx.fillStyle = settings.fontColor;
                        ctx.font = settings.fontSize + " " + settings.fontFamily;
                        ctx.textAlign = "center";
                        ctx.textBaseline = "middle";
                        $(".defeat span").html(a + "%");
                        ctx.fillText(nums + "天", hw, hh);
                    }
                };
                var numSpeed = settings.speed * (settings.percentage / settings.num);
                setTimeout(function num() {
                    if (nums < settings.num) {
                        nums++;
                        setTimeout(num, numSpeed);
                    }
                }, numSpeed);
                setTimeout(function c() {
                    l(f(a), f(a + 1));
                    if (a < settings.percentage) {
                        a += 1;
                        setTimeout(c, settings.speed);
                    }
                }, settings.speed);
            };
            $(this).attr('width', settings.width);
            $(this).attr('height', settings.height);
            this.draw();
        };
        var per, mark;
        var loadding;
        var nowTime = new Date();
        var y = nowTime.getFullYear();
        var m = (nowTime.getMonth() + 1) < 10 ? '0' + (nowTime.getMonth() + 1) : (nowTime.getMonth() + 1);
        var today = y + '-' + m + '-' + '01';
        $.ajax({
            url: io.sign.signMark,
            type: 'get',
            data: {
                dateTime: today
            },
            dataType: 'json',
            beforeSend: function () {
                loadding = $.loading({
                    content: '请稍后...'
                })
            },
            success: function (data) {
                console.log(data);
                data.qiandao.forEach(function (a, i) {
                    if (a) {
                        var t = new Date(a.day),
                            y = t.getFullYear(),
                            m = (t.getMonth() + 1) < 10 ? '0' + (t.getMonth() + 1) : (t.getMonth() + 1),
                            d = t.getDate() < 10 ? '0' + t.getDate() : t.getDate();
                        data.qiandao[i] = y + '-' + m + '-' + d
                    }
                });
                mark = data.qiandao;
                // console.log(mark);
                per = Math.round(Number(data.paiming));
                loadding.loading("hide");
                $('.per').signPer({
                    num: mark.length,
                    width: 7 * rem,
                    height: 7 * rem,
                    percentage: per,
                    speed: 10,
                    diameter: 3 * rem,
                    roundedLine: true,//圆角
                    showRemaining: true,//剩余
                    fontSize: 1.5 * rem + "px",
                    fontFamily: 'sans-serif',
                    fontColor: '#00b0ff',
                    lineColor: '#00b0ff',
                    showText: true,
                    lineWidth: .7 * rem,
                    remainingLineColor: '#ebeff3'
                });
                //点击签到
                var options = {
                    width: '100%',
                    height: '18rem',
                    showMark: true,
                    timeRange: {
                        startYear: 1949,
                        endYear: 2199
                    },
                    mark: mark
                };
                var myCalendar = new SimpleCalendar('#calendar', options);
            },
            error: function () {
                loadding.loading("hide");
                $.tips({
                    content: '服务器忙...',
                    stayTime: 2000,
                    type: "warn"
                });
                $(".ui-poptips-cnt i").addClass("icon iconfont icon-tishi");
            }
        });


    };
    pro.vip = function () {
        $('.vip .check').tap(function () {
            if ($(this).data('href')) {
                location.href = $(this).data('href');
            }
        });
        var loadding;
        $.ajax({
            url: io.vip.cardList,
            type: 'get',
            data: {},
            dataType: 'json',
            beforeSend: function () {
                loadding = $.loading({
                    content: '请稍后...'
                })
            },
            success: function (data) {
                loadding.loading("hide");
                $(".balance span").html(data.balance);
                $("footer img").attr("src", data.ewmUrl);
            },
            error: function () {
                loadding.loading("hide");
                $.tips({
                    content: '服务器忙...',
                    stayTime: 2000,
                    type: "warn"
                });
                $(".ui-poptips-cnt i").addClass("icon iconfont icon-tishi");
            }
        });


    };

    pro.shopList = function () {
        pro.list();
        $(".img-box").tap(function () {
            $("body").append('<div class="modal"></div>');
            var i = $(this).index();
            $(".introduce" + i).addClass("active");
        });
        $(".introduce>div i.icon-close").click(function () {
            $(".modal").remove();
            $(".introduce").removeClass("active");
        });

        $('.bottom li').click(function () {
            if ($(this).data('href')) {
                location.href = $(this).data('href');
            }
        });

    };

    pro.productList = function () {
        pro.list();
        // var indexObj = {};
        // for (var n = 0; n < $(".goodsList").length; n++) {
        //     indexObj["index" + n] = 0;
        // }
        // $(".img-box").tap(function () {
        //     console.log(this)
        //     $('.arrow_left').off();
        //     $('.arrow_right').off();
        //     $(".goodsList").off()
        //     var i = $(this).index();
        //     var goodsList = $(".goodsList" + i);
        //     goodsList.addClass("active");
        //     var ul = goodsList.find('.goodsList-list');
        //     var len = ul.find("li").length;
        //     var left = goodsList.find('.arrow_left');
        //     var right = goodsList.find('.arrow_right');
        //
        //
        //     goodsList.on("touchmove", function (e) {
        //         e.preventDefault();//禁止微信下拉
        //     });
        //     goodsList.swipeLeft(function () {
        //         right.click();
        //     });
        //     goodsList.swipeRight(function () {
        //         left.click();
        //     });
        //     left.click(function () {
        //         indexObj["index" + i]--;
        //         if (indexObj["index" + i] < 0) {
        //             indexObj["index" + i] = len - 1;
        //         }
        //         ul.css({marginLeft: -indexObj["index" + i] * 18.75 + "rem"});
        //     });
        //     right.click(function () {
        //         indexObj["index" + i]++;
        //         if (indexObj["index" + i] > len - 1) {
        //             indexObj["index" + i] = 0;
        //         }
        //         ul.css({marginLeft: -indexObj["index" + i] * 18.75 + "rem"});
        //     });
        // });
        // $(".goodsList-top").tap(function () {
        //         $(".goodsList").removeClass("active");
        //     }
        // );


    };

    pro.staff = function () {
        $(function () {
            var loadding;
            $.ajax({
                url: io.staff.staffWord,
                type: 'get',
                data: {},
                dataType: 'json',
                beforeSend: function () {
                    loadding = $.loading({
                        content: '请稍后...'
                    })
                },
                success: function (data) {
                    console.log(data)
                    loadding.loading("hide");
                    $(".staff").removeClass("smodal");
                    renderData(data.Staff)
                },
                error: function () {
                    loadding.loading("hide");
                    $.tips({
                        content: '服务器忙...',
                        stayTime: 2000,
                        type: "warn"
                    });
                    $(".ui-poptips-cnt i").addClass("icon iconfont icon-tishi");
                }
            });

            function renderData(data) {
                $(".staffs .img-box").css("background-image", "url(" + data[0].img + ")");
                $(".star .img-box").css("background-image", "url(" + data[1].img + ")");
                $(".news .img-box").css("background-image", "url(" + data[2].img + ")");
                $(".read .img-box").css("background-image", "url(" + data[3].img + ")");
                var m = $(".main");
                var h = m.height() - parseInt($("html").css("font-size")) * 7;
                m.height(h);
                $('.circle').click(function () {
                    if ($(this).data('href')) {
                        location.href = $(this).data('href');
                    }
                });
            }

        })
    };


    pro.staffList = function (list) {
        // var loadding = $.loading({
        //     content: '加载中...'
        // });
        var qs = location.href.length > 0 ? location.href.split("index=") : "";
        var imgList = $(".details").find("img")
        // var imgNum = imgList.length;
        // console.log(imgList)
        // imgList.each(function (index,ele) {
            // imgNum--;
            // if (imgNum > 0) {
            //     return;
            // }
            // console.log("-------"+imgNum)
            // console.log(ele)
           // ele.onload = function(){
               // imgNum--;
               // console.log(imgNum)
               // if(imgNum<=0){
                   // loadding.loading("hide");
                   main();
               // }
           // };



            // setTimeout(function () {
            //     loadding.loading("hide");
            //     main();
            // }, 200)

        // });


        function main() {
            var cHeight = document.documentElement.clientHeight;
            var h1 = cHeight / 3;
            var h2 = 2 * cHeight / 3;
            var h3 = cHeight / 2;
            var box1 = $(".details");
            var box2 = $("body");
            var scrollInterval1, scrollInterval2;
            var oTimer2 = 0;
            var initTop = 0;


            var i = parseInt(qs[1]) || 0;
            if ($(".img-detail").eq(0).height() < h3) {
                box1.prepend('<div class="ding ding-t"></div>');
                if ($(".img-detail").eq(i).height() > h3) {
                    initTop = h1;
                }
            }
            if ($(".img-detail").eq(0).height() > h3 && $(".img-detail").eq(i).height() < h3) {
                // initTop=h1;
                initTop = -h1;
            }
            // clearTimeout(oTimer1);
            // clearTimeout(oTimer2);
            $(".mask").height(h1);

            $(".img-detail").each(function (index, ele) {
                if ($(this).height() > h3) {
                    $(this).height(h2);
                } else {
                    $(this).height(h1);
                }
                if (index < i) {
                    initTop += $(this).height();
                    // console.log(initTop)
                }

            });
            $(".ding").height(h1);
            box1.scrollTop(initTop);
            // clearTimeout(oTimer1);
            // clearTimeout(oTimer2);
            changeMask(i);
            // var sTop,eTop;
            //
            var touchEvents = {
                touchstart: function () {
                    //clearInterval(scrollInterval1);
                    //clearInterval(scrollInterval2);
                    // clearTimeout(oTimer1);
                    // clearTimeout(oTimer2);
                    //$(".mask").css("opacity", 0);
                    //$(".mask1").css("top", "-100%");
                    //$(".mask2").css("bottom", "-100%");
                },
                touchend: function () {
                    //clearTimeout(oTimer1);
                    //clearTimeout(oTimer2);
                    //changeMask(i);
                    //setTimeout(function(){
                    //    $(".mask2").css("opacity", .85);
                    //    $(".mask2").css("bottom", 0);
                    //},500)
                }
            };
            //box2.on(touchEvents);

            box2.on('touchmove', function (event) {
                event.preventDefault();
            });
            box2.on('mousewheel', function (event) {
                event.preventDefault();
            });
            var sTop, cTop;
            box2.on("swipeUp", Up);
            box2.on("swipeDown", Down);


            function Up() {
                $(".mask1").css("top", "-100%");
                $(".mask2").css("bottom", "-100%");
                box2.off("swipeUp", Up);
                box2.off("swipeDown", Down);
                // alert("-")
                clearInterval(scrollInterval1);
                clearInterval(scrollInterval2);
                // console.log("+++++++++++++++++++")
                clearTimeout(oTimer2);
                // box2.append('<div class="top-modal"></div>');
                // console.log("1+")
                if (i < list.length - 1) {
                    i++;
                    sTop = box1.scrollTop();
                    scrollInterval1 = setInterval(function () {
                        cTop = box1.scrollTop();
                        if (cTop < sTop + $(".img-detail").eq(i).height()) {
                            box1.scrollTop(cTop + 4)
                        } else {
                            box1.scrollTop(sTop + $(".img-detail").eq(i).height());
                            clearInterval(scrollInterval1);
                            //$(".top-modal").remove();
                            box2.on("swipeUp", Up);
                            box2.on("swipeDown", Down);
                            // console.log("11-")
                            // alert("++")
                        }
                    }, 5);
                    // clearTimeout(oTimer1);
                    // clearTimeout(oTimer2);
                    // changeMask(i);
                } else {
                    //$(".mask1").css("opacity", 0);
                    //$(".mask1").css("top", "-100%");
                    //console.log("+")
                    //$(".top-modal").remove();
                    // console.log("12-")
                    box2.on("swipeUp", Up);
                    box2.on("swipeDown", Down);
                    // alert("+")
                }

                // console.log(i)
                changeMask(i)
            }

            function Down() {
                // alert(i)
                $(".mask1").css("top", "-100%");
                $(".mask2").css("bottom", "-100%");
                box2.off("swipeUp", Up);
                box2.off("swipeDown", Down);
                // alert("-")
                clearInterval(scrollInterval1);
                clearInterval(scrollInterval2);
                // console.log("=========================")
                clearTimeout(oTimer2);
                // box2.append('<div class="top-modal"></div>');
                // console.log("2+")
                if (i > 0) {
                    i--;
                    sTop = box1.scrollTop();
                    scrollInterval2 = setInterval(function () {
                        cTop = box1.scrollTop();
                        if (cTop > sTop - $(".img-detail").eq(i + 1).height()) {
                            box1.scrollTop(cTop - 4)
                        } else {
                            box1.scrollTop(sTop - $(".img-detail").eq(i + 1).height());
                            clearInterval(scrollInterval2);
                            //$(".top-modal").remove();
                            box2.on("swipeUp", Up);
                            box2.on("swipeDown", Down);
                            // console.log("21-")
                            // alert("ii"+i)
                            // alert("++")
                        }
                    }, 5);
                    // clearTimeout(oTimer1);
                    // clearTimeout(oTimer2);
                    // changeMask(i)
                } else {
                    //$(".mask1").css("opacity", 0);
                    //$(".mask1").css("top", "-100%");
                    //$(".top-modal").remove();
                    // console.log("22-")
                    box2.on("swipeUp", Up);
                    box2.on("swipeDown", Down);
                    // alert("+")
                    // alert("iii"+i)
                }

                changeMask(i)
                // console.log(i)
                // alert("iiii"+i)
            }

            function changeMask(i) {
                clearTimeout(oTimer2);
                // console.log(i)
                // console.log("---"+$(".img-detail").eq(i).height())
                if ($(".img-detail").eq(i).height()) {
                    clearTimeout(oTimer2);
                    //console.log(i);
                    //console.log($(".img-detail").eq(i).height());
                    if ($(".img-detail").eq(i).height() < h3) {
                        oTimer2 = setTimeout(function () {
                            $(".mask2").css("opacity", .85);
                            $(".mask2").css("bottom", 0);
                            $(".mask1").css("opacity", .85);
                            $(".mask1").css("top", 0);
                        }, 500);
                        //console.log("b")

                    } else {
                        clearTimeout(oTimer2);
                        $(".mask1").css("opacity", 0);
                        $(".mask1").css("top", "-100%");
                        //console.log("a");
                        oTimer2 = setTimeout(function () {
                            $(".mask2").css("opacity", .85);
                            $(".mask2").css("bottom", 0);
                        }, 500);
                    }

                }
                $(".p1").html(list[i].job)
                $(".p2").html(list[i].userName || list[i].nickname)
                $(".p3").html(list[i].staffDesc)
            }
        }

    };

    pro.weekStart = function () {
        var loadding;
        $.ajax({
            url: io.staff.weekStar,
            type: 'get',
            data: {},
            dataType: 'json',
            beforeSend: function () {
                loadding = $.loading({
                    content: '请稍后...'
                })
            },
            success: function (data) {
                console.log(data);
                loadding.loading("hide");
                $(".modal").remove();
                renderData(data);
            },
            error: function () {
                loadding.loading("hide");
                $.tips({
                    content: '服务器忙...',
                    stayTime: 2000,
                    type: "warn"
                });
                $(".ui-poptips-cnt i").addClass("icon iconfont icon-tishi");
            }
        });
        function renderData(data) {
            $(".star").attr("src", data.topImg);
            $("header div span").html(data.title);
            // $("header h3").html(data.title);
            $(".top time").html(data.createTimeString);
            $(".top span").html(data.like);
            $("article section").html(data.content);
            $(".parse").attr("data-id", data.id)
        }

        $(".parse").click(function () {
            if (!$(this).hasClass("parsed")) {
                var praiseCount = $(this).siblings("span");
                // if ($(this).hasClass("parsed")) {
                //     // praiseCount.html(+praiseCount.html() - 1)
                //     return false;
                // } else {
                //     $(this).addClass("parsed");
                //     praiseCount.html(+praiseCount.html() + 1)
                // }
                // $(this).toggleClass("parsed");
                $.ajax({
                    url: io.staff.like,
                    type: 'get',
                    data: {
                        id: $(".parse").data("id")
                    },
                    dataType: 'json',
                    success: function (data) {
                        console.log(data);
                        if (data.result == "success") {
                            praiseCount.html(+praiseCount.html() + 1);
                            $(".parse").addClass("parsed");
                        } else {
                            $.tips({
                                content: '您已点过赞',
                                stayTime: 2000,
                                type: "warn"
                            });
                        }
                    },
                    error: function () {
                        $.tips({
                            content: '服务器忙...',
                            stayTime: 2000,
                            type: "warn"
                        });
                        $(".ui-poptips-cnt i").addClass("icon iconfont icon-tishi");
                    }
                });
            }


        });

    };

    pro.brandRecommend = function () {
        var shopId = location.href.length > 0 ? location.href.split("shopId=")[1] : "";
        var shopName = location.href.length > 0 ? location.href.split("shopName=")[1] : "";
        $("h2").html(decodeURI(shopName));
        var loadding;
        var sessionData = "";
        $.ajax({
            url: io.shop.recommend,
            type: 'get',
            data: {
                shopId: parseInt(shopId)
            },
            dataType: 'json',
            beforeSend: function () {
                loadding = $.loading({
                    content: '请稍后...'
                })
            },
            success: function (data) {
                console.log(data)
                sessionData = data;
                setTimeout(function () {
                    loadding.loading("hide");
                    $(".modal").remove();
                }, 200);
                renderData(data);
            },
            error: function () {
                loadding.loading("hide");
                $.tips({
                    content: '服务器忙...',
                    stayTime: 2000,
                    type: "warn"
                });
                $(".ui-poptips-cnt i").addClass("icon iconfont icon-tishi");
            }
        });
        function renderData(data) {/* onclick="location.href=\'brandDetail.html?shopId=' + value[i].shopId + '\'"*/
            $.each(data, function (key, value) {
                // console.log(value);
                var html = "";
                for (var i = 0; i < value.length; i++) {
                    html += '<div class="ui-col ui-col-33 logo-img" data-shop="' + value[i].shopId + '" data-category="' + value[i].categoryName + '"><img src="img/loading.gif" data-original="' + value[i].logo + '" alt=""></div>'
                }
                var h3 = '<h3>' + key + '</h3>';
                $("body").append(h3 + '<div class="clearfix">' + html + '</div>')
            });
            $('img').picLazyLoad({
                threshold: 20
            });

            $(".logo-img").tap(function () {
                sessionStorage.setItem("cx_logoList", JSON.stringify(sessionData));
                location.href = 'brandDetail.html?shopId=' + $(this).data("shop") + '&categoryName=' + $(this).data("category");
            })

        }

    };

    pro.brandDetail = function () {
        var loadding = $.loading({
            content: '请稍后...'
        });
        var id = parseInt(location.href.length > 0 ? location.href.split("shopId=")[1] : "");
        var name = decodeURI(location.href.length > 0 ? location.href.split("categoryName=")[1] : "");
        var data = JSON.parse(sessionStorage.getItem("cx_logoList") || '{}');
        var detailData = "";
        if (name != "undefined") {
            data[name].forEach(function (ele, index) {
                if (ele.shopId == id) {
                    detailData = ele;
                }
            });
        } else {
            console.log(data);
            $.each(data,function (index) {
                console.log(this);
                if (this.shopId == id) {
                    detailData = this;
                    return false;
                }
            });
        }

        // console.log(detailData);
        if (detailData) {
            setTimeout(function () {
                loadding.loading("hide");
                $(".modal").remove();
                renderData(detailData)
            }, 200);
        }
        // $.ajax({
        //     url: io.brand.detail,
        //     type: 'get',
        //     data: {
        //         shopId: i
        //     },
        //     dataType: 'json',
        //     beforeSend: function () {
        //         loadding = $.loading({
        //             content: '请稍后...'
        //         })
        //     },
        //     success: function (data) {
        //         console.log(data)
        //         setTimeout(function () {
        //             loadding.loading("hide");
        //             $(".modal").remove();
        //         }, 200);
        //         renderData(data.info);
        //     },
        //     error: function () {
        //         loadding.loading("hide");
        //         $.tips({
        //             content: '服务器忙...',
        //             stayTime: 2000,
        //             type: "warn"
        //         });
        //         $(".ui-poptips-cnt i").addClass("icon iconfont icon-tishi");
        //     }
        // });
        function renderData(data) {
            $("header>img").attr("src", data.img);
            $("header div img").attr("src", data.logo);
            $(".info-top p").eq(0).find("span").html(data.shopName);
            $(".info-top p").eq(1).find("span").html(data.floorName);
            // $(".info-bottom h3").html(data.title);
            $(".info-bottom p").html(data.description);
        }

    };

    pro.floorGuide = function () {
        var storeId = location.href.length > 0 ? location.href.split("shopId=")[1] : "";
        var loadding;
        $.ajax({
            url: io.shop.getFloorByStoreId,
            type: 'get',
            data: {
                storeId: storeId
            },
            dataType: 'json',
            beforeSend: function () {
                loadding = $.loading({
                    content: '请稍后...'
                })
            },
            success: function (data) {
                console.log(data)
                setTimeout(function () {
                    loadding.loading("hide");
                    $(".modal").remove();
                }, 200);
                renderData(data.Floor);
            },
            error: function () {
                loadding.loading("hide");
                $.tips({
                    content: '服务器忙...',
                    stayTime: 2000,
                    type: "warn"
                });
                $(".ui-poptips-cnt i").addClass("icon iconfont icon-tishi");
            }
        });

        var getRandomColor = function(){
            var a=Math.round(Math.random()*0x1000000);
            var c="00000".concat(a.toString(16));
            return "#"+c.substr(c.length-6,6);
        };
        function renderData(data) {
            $("header img").attr("src", data[0].img);
            var html = "";
            for (var i = 0; i < data.length; i++) {
                var color = getRandomColor();
                html += '<li class="divide" data-store="' + data[i].storeId + '" data-floor="' + data[i].id + '">' +
                    '<i class="i-color" style="background: '+getRandomColor()+'"></i>' +
                    '<span>' + data[i].floorName + '</span>' +
                    '<i class="icon iconfont icon-icon07-copy1"></i>' +
                    '</li>'
            }
            $(".floor-list").html(html);


            $(".ui-list li").click(function () {
                var sendData = {
                    storeId: $(this).data("store"),
                    floorId: $(this).data("floor")
                };
                $.ajax({
                    url: io.shop.getTblShopByFloorId,
                    type: 'get',
                    data: sendData,
                    dataType: 'json',
                    success: function (data) {
                        console.log(data);
                        console.log(sendData);
                        renderLogo(data.TblShop);
                    },
                    error: function () {
                        $.tips({
                            content: '服务器忙...',
                            stayTime: 2000,
                            type: "warn"
                        });
                        $(".ui-poptips-cnt i").addClass("icon iconfont icon-tishi");
                    }
                });

            });

            function renderLogo(data) {
                var html = "";
                for (var i = 0; i < data.length; i++) {
                    html += '<div class="ui-col ui-col-33 logo-img" data-shop="' + data[i].shopId + '"><img src="' + data[i].logo + '"></div>'
                }

                $.dialog({
                    content: html,
                    button: ["关闭"]
                });

                $(".logo-img").click(function () {
                    sessionStorage.setItem("cx_logoList", JSON.stringify(data));
                    location.href = 'brandDetail.html?shopId=' + $(this).data("shop");
                })
            }


        }


    }

};
